package com.yejiarong.influxdb.service.impl;

import com.alibaba.fastjson2.JSON;
import com.yejiarong.common.validate.ValidateUtils;
import com.yejiarong.influxdb.api.bean.request.SavePointRequest;
import com.yejiarong.influxdb.service.IInfluxdbService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

/**
 * @author YeJR
 */
@Slf4j
@Service
public class InfluxdbServiceImpl implements IInfluxdbService {

    private final RabbitTemplate rabbitTemplate;

    public InfluxdbServiceImpl(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    /**
     * 收集 point
     * @param exchange 消息队列
     * @param point point
     */
    @Override
    public void collectPoint(String exchange, SavePointRequest point) {
        ValidateUtils.valid(point);
        rabbitTemplate.convertAndSend(exchange, "*", JSON.toJSONString(point));
    }
}
